﻿using B.S.BaseData.Domain.Entities;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Write.API.Command.LeaveCommand;
using B.S.BaseData.Write.API.Command.MenuCommand;
using B.S.BaseData.Write.API.Command.RoleCommand;
using B.S.BaseData.Write.API.Command.RoleMenuCommand;
using B.S.BaseData.Write.API.Command.UserCommand;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BaseData.Write.API.Controllers
{
    /// <summary>
    /// API控制器-写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly IMediator mediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public UserController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        #region 用户
        /// <summary>
        /// 用户添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> AddUser(AddUserCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 用户删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> DelUser(DelUserCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 用户修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> UpdUser(UpdUserCommand request)
        {
            return mediator.Send(request);
        }

        #endregion

        #region 角色

        /// <summary>
        /// 新增角色
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> AddRole(AddRoleCommand request)
        {
            return mediator.Send(request);
        }



        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> DelRole(RoleDelCommand request)
        {
            return mediator.Send(request);
        }


        /// <summary>
        /// 修改角色
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> RoleUpdate(RoleUpdateCommand request)
        {
            return mediator.Send(request);
        }


        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<object>> UserRoleAddRanges(UserRoleCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 批量删除用户角色关系表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<string>> RemoveUserRole(RemoveUserRoleCommand request)
        {
            return await mediator.Send(request);
        }


        /// <summary>
        /// 通过角色ID批量删除关系表
        /// </summary>
        [HttpPost]
        public async Task<APIResult<string>> UserRoleRemoveRange(RemoveRoleIdCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 菜单

        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> DelMenu(DelMenuCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 新增菜单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> CreateMenu(CreateMenuCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 更新菜单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> UpdMenu(UpdMenuCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 批量删除角色和菜单关系
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public Task<APIResult<int>> DelRangeRoleMenu([FromQuery] DelRangeRoleMenuCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 批量添加角色菜单关系
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>任务</returns>
        [HttpPost]
        public Task<APIResult<int>> Handle(AddRangeRoleMenuCommand request)
        {
            return mediator.Send(request);
        }



        #endregion


        /// <summary>
        /// 新增请假申请
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> CreateLeave(CreateLeaveCommand request)
        {
            return await mediator.Send(request);

        }

        /// <summary>
        /// 删除请假申请
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public Task<APIResult<int>> DelLeave([FromQuery] DelLeaveCommand request)
        {

            return mediator.Send(request);
        }

        /// <summary>
        /// 修改请假申请
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>任务</returns>
        [HttpPost]
        public Task<APIResult<int>> UpdateLeave(UpdLeaveCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 审批
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>任务</returns>
        [HttpPost]
        public Task<APIResult<int>> ApprovalLeave(ApprovalLeaveCommand request)
        {
            return mediator.Send(request);
        }
    }
}
